package com.wac.data.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wac.data.service.ArticleService;
import com.wac.data.service.DynamicService;
import com.wac.data.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/search")
public class SearchController {

	private static ObjectMapper objectMapper = new ObjectMapper();

	@Resource
	private ArticleService articleService;
	@Resource
	private DynamicService dynamicService;
	@Resource
	private UserService userService;


	@RequestMapping("/article")
	public String articleSearch(String text, int page) throws JsonProcessingException {
		return objectMapper.writeValueAsString(articleService.search(text, page));
	}

	@RequestMapping("/dynamic")
	public String dynamicSearch(String text, int page) throws JsonProcessingException {
		return objectMapper.writeValueAsString(dynamicService.search(text, page));
	}

	@RequestMapping("/user")
	public String userSearch(String text, int page) throws JsonProcessingException {
		return objectMapper.writeValueAsString(userService.search(text, page));
	}

}
